<!--河南星辰软件科技有限公司
@copyright Copyright (c) 2010~2022 All rights reserved.
-->
<template>
  <div class='app-container'>
    <el-row>
      <el-col :span='22' :xs='24'>
        <el-menu default-active='active' mode='horizontal' class='menu-unit'>
          <el-menu-item v-for='item in Container2' :index="'基本信息'===item.name?'active':'default'">
            <el-link @click="gotoMenu(item.url)" :type="'基本信息'===item.name?'primary':'default'">{{item.page_desc||item.name}}</el-link>
          </el-menu-item>
        </el-menu>
        <table cellpadding="4" cellspacing="0" border="0" width="100%">
          <tr>
            <td class="containerBack">
              <el-form ref="form" :model="person_info" :rules="rules" label-width="100px" id="mvcfm">
                <el-button @click="customerContactsUpSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
                <el-button @click="gotoPage('/crm/sale/CustomerContactsDet?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>返回</el-button>
                <div class="form-unit">
                  <span class="mvc-title-left"> 添加联系人 </span>
                </div>
                <div>
                  <el-row>
                    <el-col :span="24">
                      <el-form-item label="联系人类型" prop="contact_oneorclient">
                        <el-radio-group v-model="person_info.contact_oneorclient">
                          <el-radio-button label="技术类">技术类</el-radio-button>
                          <el-radio-button label="管理类">管理类</el-radio-button>
                        </el-radio-group>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="所属部门" prop="person_dept">
                        <el-input v-model="person_info.person_dept" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="英文名" prop="english_name">
                        <el-input v-model="person_info.english_name" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="姓名" prop="person_name">
                        <el-input v-model="person_info.person_name" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="24">
                      <el-form-item label="性别" prop="person_sex">
                        <el-radio-group v-model="person_info.person_sex">
                          <el-radio-button label="男">男</el-radio-button>
                          <el-radio-button label="女">女</el-radio-button>
                        </el-radio-group>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="岗位" prop="person_station">
                        <el-input v-model="person_info.person_station" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="附加名称" prop="nick_name">
                        <el-input v-model="person_info.nick_name" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="出生日期" prop="person_birthday">
                        <el-date-picker v-model="person_info.person_birthday" type="date" style='width:100%' value-format="yyyy-MM-dd" />
                      </el-form-item>
                    </el-col>
                  </el-row>
                </div>
                <div class="form-unit">
                  <span class="mvc-title-left"> 电话号码 </span>
                </div>
                <el-table :data="phones_info">
                  <el-table-column label="类型" prop="phones_type" 类型>
                    <template slot-scope="scope">
                      <el-select style='width:100%' v-model="scope.row.phones_type">
                        <el-option label="－－无－－" value='' />
                        <el-option v-for="dict in phonetype" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column label="区号" prop="phone_area">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.phone_area" />
                    </template>
                  </el-table-column>
                  <el-table-column label="号码" prop="phones_number">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.phones_number" />
                    </template>
                  </el-table-column>
                  <el-table-column label="分机" prop="phones_extension">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.phones_extension" />
                    </template>
                  </el-table-column>
                </el-table>
                <div class="form-unit">
                  <span class="mvc-title-left"> 电子邮件地址 </span>
                </div>
                <el-table :data="email_info">
                  <el-table-column label="类型" prop="email_type" 类型>
                    <template slot-scope="scope">
                      <el-select style='width:100%' v-model="scope.row.email_type">
                        <el-option label="－－无－－" value='' />
                        <el-option v-for="dict in emailtype" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column label="邮件地址" prop="email_address">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.email_address" />
                    </template>
                  </el-table-column>
                </el-table>
                <div class="form-unit">
                  <span class="mvc-title-left"> 即时通讯地址 </span>
                </div>
                <el-table :data="contact_ifno">
                  <el-table-column label="类型" prop="contact_pritype" 类型>
                    <template slot-scope="scope">
                      <el-select style='width:100%' v-model="scope.row.contact_pritype">
                        <el-option label="－－无－－" value='' />
                        <el-option v-for="dict in momentcon" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column label="类型2" prop="contact_lestype" 类型2>
                    <template slot-scope="scope">
                      <el-select style='width:100%' v-model="scope.row.contact_lestype">
                        <el-option label="－－无－－" value='' />
                        <el-option v-for="dict in momentconano" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column label="号码" prop="contact_number">
                    <template slot-scope="scope">
                      <el-input v-model="scope.row.contact_number" />
                    </template>
                  </el-table-column>
                </el-table>
                <div class="form-unit">
                  <span class="mvc-title-left"> 地址 </span>
                </div>
                <div>
                  <input type="hidden" id="address_id" name="address_id" :value="address.address_id">
                  <el-row>
                    <el-col :span="12">
                      <el-form-item label="地址类型" prop="address_type">
                        <el-select style='width:100%' v-model="address.address_type">
                          <el-option label="注册地" value="注册地" />
                          <el-option label="生产地" value="生产地" />
                          <el-option label="研发地" value="研发地" />
                          <el-option label="销售地" value="销售地" />
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="24">
                      <el-form-item label="地区" prop="address_nation">
                        <el-select v-model="address.address_nation">
                          <el-option label="中国" value="中国" />
                          <el-option label="海外" value="海外" />
                        </el-select> 省 <el-select v-model="address.address_province" @change="list_s_province">
                          <el-option label="－－无－－" value='' />
                          <el-option v-for="dict in s_province" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
                        </el-select> 市 <el-select v-model="address.address_city" @change="list_s_city">
                          <el-option label="－－无－－" value='' />
                          <el-option v-for="dict in s_city" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
                        </el-select> 县 <el-select v-model="address.address_town">
                          <el-option label="－－无－－" value='' />
                          <el-option v-for="dict in s_district" :key="dict.__code" :label="dict.__desc" :value="dict.__code"></el-option>
                        </el-select>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="24">
                      <el-form-item label="邮政编码" prop="address_postcode">
                        <div class="el-select">
                          <el-input type="text" v-model="address.address_postcode" />
                        </div>
                        <el-button @click="popPotentialPostcodeChoice('address_postcode','address_postcode')" type="success" size="mini"><i class="fa fa-edit"></i>选择</el-button>
                      </el-form-item>
                    </el-col>
                  </el-row>
                  <el-row>
                    <el-col :span="24">
                      <el-form-item label="详细地址" prop="address_info">
                        <el-input type="textarea" v-model="address.address_info" ttparea=350></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </div>
                <div class="form-unit">
                  <span class="mvc-title-left"> 额外明细 </span>
                </div>
                <div>
                  <el-row>
                    <el-col :span="24">
                      <el-form-item label="备注" prop="remark">
                        <el-input type="textarea" v-model="person_info.remark" ttparea=350></el-input>
                      </el-form-item>
                    </el-col>
                  </el-row>
                </div>
                <el-button @click="customerContactsUpSubmit('')" type='success' size="mini"><i class='fa fa-check'></i>保存</el-button>
                <el-button @click="gotoPage('/crm/sale/CustomerContactsDet?'+vueparams+'')" type='primary' size="mini"><i class='fa fa-reply'></i>返回</el-button>
              </el-form>
            </td>
          </tr>
        </table>
      </el-col>
      <el-col :span='2' :xs='24'>
        <el-menu default-active='active' class='menu-unit'>
          <el-menu-item v-for='item in Container'>
            <el-link @click="gotoMenu(item.url)" :type="'联系人'===item.name?'primary':'default'">{{item.page_desc||item.name}}</el-link>
          </el-menu-item>
        </el-menu>
      </el-col>
    </el-row>
    <el-dialog :visible.sync="PotentialPostcodeChoiceVisible" append-to-body>
      <PotentialPostcodeChoice v-if="PotentialPostcodeChoiceVisible" ref="PotentialPostcodeChoice" :popparams="popparams"> </PotentialPostcodeChoice>
    </el-dialog>
  </div>
</template>
<script>
  import request from '@/utils/request'
  import PotentialPostcodeChoice from "@/views/crm/sale/potential/PotentialPostcodeChoice";
  export default {
    name: 'CustomerContactsUp',
    components: {
      PotentialPostcodeChoice,
    },
    props: ['popparams'],
    data() {
      return {
        PotentialPostcodeChoiceVisible: false,
        PotentialPostcodeChoiceValue: null,
        PotentialPostcodeChoiceDesc: null,
        vueparams: this.getVUEParams(""),
        person_info: {
          contact_oneorclient: null,
          person_dept: null,
          english_name: null,
          person_name: null,
          person_sex: null,
          person_station: null,
          nick_name: null,
          person_birthday: null,
        },
        phone: [],
        email_info: [],
        contact_ifno: [],
        address: {
          address_type: null,
          address_nation: null,
          address_province: null,
          address_city: null,
          address_town: null,
          address_postcode: null,
          address_info: null,
        },
        phones_info: [],
        phonetype: [],
        emailtype: [],
        momentcon: [],
        momentconano: [],
        s_province: [],
        s_city: [],
        s_district: [],
        loading: false,
        Container: null,
        Container2: null,
        rules: {
          person_dept: [{
            required: true,
            message: "所属部门不能为空",
            trigger: 'blur',
          }],
          person_name: [{
            required: true,
            message: "姓名不能为空",
            trigger: 'blur',
          }],
        }
      }
    },
    created() {
      this.getData();
      this.loadContainerMenu({
        pid: "80299289AF2443B18EA545A4C0C37170",
        name: "客户管理右菜单",
        selected: "联系人"
      }, 'Container', this.vueparams);
      this.loadContainerMenu({
        pid: "14ED91704E794C43A973E8BEFF724C15",
        name: "客户联系人右菜单",
        selected: "基本信息"
      }, 'Container2', this.vueparams);
    },
    updated() {},
    mounted() {},
    methods: {
      getData() {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/crm/sale/CustomerContacts/customerContactsUp?' + this.vueparams,
        }).then(data => {
          for (var k in data) {
            if (Array.isArray(data[k])) {
              this[k] = data[k];
            } else {
              $.extend(this[k], data[k]);
            }
          }
        })
      },
      customerContactsUpSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/crm/sale/CustomerContacts/customerContactsUpSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/crm/sale/CustomerContactsDet/customerContactsDet?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      customerContactsPubUpSubmit(_params) {
        this.$refs["form"].validate(valid => {
          if (valid) {
            request({
              method: 'post',
              url: '/xcapi/VUEAction/crm/sale/CustomerContacts/customerContactsPubUpSubmit?' + _params + this.vueparams,
              data: this.postData()
            }).then(data => {
              this.gotoPage("/crm/sale/CustomerContactsDet/customerContactsDet?" + this.vueparams, data);
              this.msgSuccess(data.msg);
            })
          } else {
            this.msgError("必填项错误");
          }
        });
      },
      list_s_province(value) {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/crm/sale/CustomerContacts/ajaxList?' + this.vueparams,
          params: {
            htmltable: '',
            cfield_name: "address_city,address_town",
            address_province: value
          }
        }).then(data => {
          this.$set(this.address, 'address_city', '');
          this.s_city = data['address_city'];
          this.$set(this.address, 'address_town', '');
          this.s_district = data['address_town'];
        })
      },
      list_s_city(value) {
        request({
          method: 'get',
          url: '/xcapi/VUEAction/crm/sale/CustomerContacts/ajaxList?' + this.vueparams,
          params: {
            htmltable: '',
            cfield_name: "address_town",
            address_city: value
          }
        }).then(data => {
          this.$set(this.address, 'address_town', '');
          this.s_district = data['address_town'];
        })
      },
      popPotentialPostcodeChoice(desc, value) {
        this.PotentialPostcodeChoiceVisible = true;
        this.PotentialPostcodeChoiceDesc = desc;
        this.PotentialPostcodeChoiceValue = value;
      },
      closePotentialPostcodeChoice(value, desc) {
        this.PotentialPostcodeChoiceVisible = false;
        this.$set(this.address, this.PotentialPostcodeChoiceDesc, desc);
        this.$set(this.address, this.PotentialPostcodeChoiceValue, value);
      },
    },
  }
</script>
